package unused;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

public final class UnsafeUtils {
    public static Unsafe unsafe;

    private UnsafeUtils() {}

    static {
        try {
            Field f = Unsafe.class.getDeclaredField("theUnsafe");
            f.setAccessible(true);
            unsafe = (Unsafe) f.get(null);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    public static Object get(Object o, String name) {
        Field field = ReflectUtils.getField(o.getClass(), name);
        long fieldOffset = unsafe.objectFieldOffset(field);
        return unsafe.getObject(o, fieldOffset);
    }


}
